package com.wd.mondle_home.model.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.GridView
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.setPadding
import com.bumptech.glide.Glide
import com.bumptech.glide.R
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions

import com.wd.current.model.Bean.DataBean

class StackAdapter(private val context: Context, private val list: List<DataBean.FindRecommendConstellationBean.Result>) : BaseAdapter() {
    override fun getCount(): Int {
        return list.size
    }

    override fun getItem(p0: Int): Any {
        return list[p0]
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        val  view=LayoutInflater.from(context).inflate(com.wd.myhome.R.layout.constellation_matching_item,null)

        val listBean=list[p0]
        //设置图片
        val img=view.findViewById<ImageView>(com.wd.myhome.R.id.stack_image)

        Glide.with(context).load(listBean.personalImage)
            .apply(RequestOptions.bitmapTransform(RoundedCorners(30)))
            .placeholder(com.wd.myhome.R.mipmap.ic_launcher)
            .error(com.wd.myhome.R.mipmap.ic_launcher)
            .into(img)
        //设置昵称
        val  name=view.findViewById<TextView>(com.wd.myhome.R.id.name)
        name.setText(listBean.nickName)
        //设置性别图片
        val sexImg=view.findViewById<ImageView>(com.wd.myhome.R.id.sex_img)
        if (listBean.sex==1){
            sexImg.setImageResource(com.wd.myhome.R.mipmap.man)
        }else{
            sexImg.setImageResource(com.wd.myhome.R.mipmap.woman)
        }
        //设置星座图片
        val constellationImage=view.findViewById<ImageView>(com.wd.myhome.R.id.constellationImage)
        Glide.with(context).load(listBean.constellationImage)
            .placeholder(com.wd.myhome.R.mipmap.ic_launcher)
            .error(com.wd.myhome.R.mipmap.ic_launcher)
            .into(constellationImage)

        view.setPadding(16,16,16,16)
        // 修改布局参数，使得每个视图项显示在上一个项的下方
        val layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        view.layoutParams = layoutParams

        return view
    }
}